package com.sz.admin.ai.factory.embeddingFactory;

import com.sz.admin.ai.factory.embeddingFactory.Handler.EmbeddingHandler;
import com.sz.admin.ai.factory.embeddingFactory.entity.EmbeddingPlatformEnum;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @描述: 嵌入模型Handler工厂
 * @Author: TangYuan
 * @Date: 2025/2/24 15:06
 */
@Component
public class EmbeddingHandlerFactory implements InitializingBean {
    
    @Resource
    private List<EmbeddingHandler> embeddingHandlerList;

    private final Map<EmbeddingPlatformEnum, EmbeddingHandler> handlerMap = new HashMap<>();

    public EmbeddingHandler getHandler(String platformName) {
        EmbeddingPlatformEnum embeddingPlatformEnum = EmbeddingPlatformEnum.getEnumByPlatformName(platformName);
        return handlerMap.get(embeddingPlatformEnum);
    }

    @Override
    public void afterPropertiesSet() {
        for (EmbeddingHandler embeddingHandler : embeddingHandlerList) {
            handlerMap.put(embeddingHandler.getEmbeddingPlatformEnum(), embeddingHandler);
        }
    }
}